package com.my.study.controller;

import com.my.study.mq.publisher.demo.DefaultPublisher;
import com.my.study.mq.publisher.fanout.FanoutPublisher;
import com.my.study.mq.publisher.topic.TopicPublisher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: yidujun
 * @create: 2021/03/16 10:50
 */
@RestController
@Api("RabbitMQ")
public class RabbitController {

    @Autowired
    private DefaultPublisher defaultPublisher;

    @Autowired
    private FanoutPublisher fanoutPublisher;

    @Autowired
    private TopicPublisher topicPublisher;

    //=================== 普通队列 模式  ====================
    /**
     * 普通队列模式：生产 - 消费
     *
     * @return
     */
    @ApiOperation(value = "普通队列模式接口", notes = "简单测试MQ普通队列模式")
    @GetMapping("/sendDefaultQueue")
    public String sendDefaultQueue() {
//        this.defaultPublisher.sendDefaultQueue();
//        this.defaultPublisher.sendDefaultQueueList();
//        this.defaultPublisher.sendDefaultQueueUser();
        this.defaultPublisher.sendDefaultQueueListUser();
        return "success";
    }

    //=================== fanout广播模式  ====================

    /**
     * Fanout模式：生产 - 交换机 - 消费
     *
     * @return
     */
    @ApiOperation(value = "Fanout广播模式接口", notes = "简单测试MQ的Fanout模式")
    @GetMapping("/sendFanout")
    public String sendFanout() {
        this.fanoutPublisher.sendFanout();
        return "success";
    }

    //=================== topic主题模式  ====================

    /**
     * Topic模式
     * @return
     */
    @ApiOperation(value = "Topic模式-TopicAB接口", notes = "匹配topic.msg消息")
    @GetMapping("/sendTopicTopicAB")
    public String sendTopicTopicAB() {
        this.topicPublisher.sendTopicAB();
        return "success";
    }

    /**
     * Topic模式
     * @return
     */
    @ApiOperation(value = "Topic模式-TopicB接口", notes = "匹配topic.#消息")
    @GetMapping("/sendTopicTopicB")
    public String sendTopicTopicB() {
        this.topicPublisher.sendTopicB();
        return "success";
    }

    /**
     * Topic模式
     * @return
     */
    @ApiOperation(value = "Topic模式-TopicBC接口", notes = "匹配topic.x.z消息")
    @GetMapping("/sendTopicTopicBC")
    public String sendTopicTopicBC() {
        this.topicPublisher.sendTopicBC();
        return "success";
    }

}
